//自定义一些指令并作为插件返回
import {useIntersectionObserver} from "@vueuse/core";

export const lazyPlugin = {
    install(app) {
        app.directive('img-lazy', {
            mounted(el, binding) {
                const {stop} = useIntersectionObserver(
                        el, ([{isIntersecting}]) => {
                            // console.log(isIntersecting)
                            if (isIntersecting) {
                                el.src = binding.value  //为啥是src？
                                stop() //防止一直重复判断
                            }
                        }
                )
            }
        })
    }
}